package com.citywy.controller;

import com.citywy.domain.Account;
import com.citywy.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 账户操作控制器类
 */
@Controller
@RequestMapping("account")
public class AccountController {

    @Autowired
    AccountService accountService;

    @RequestMapping("list")
    public ModelAndView findAllAccount(){
        ModelAndView res = new ModelAndView("pages/list");
        List<Account> list = accountService.findAllAccount();
        res.addObject("list",list);
        return res;
    }

    @RequestMapping("add")
    public String addAccount(HttpServletRequest request, Account account){
        System.out.println(account);
        //不是以.htm结尾,返回404
        if(!request.getRequestURI().endsWith(".htm")){
            return "pages/404";
        }
        //执行添加操作！
        accountService.saveAccount(account);
        return "pages/success";
    }
}
